﻿using B.S.Passport.Domain;
using B.S.Passport.ErrorCode;
using B.S.Passport.Infacetrue;
using B.S.Passport.Write.API.Application;
using DAL;
using MediatR;

namespace B.S.Passport.Write.API.ApplicationHander
{
    public class UpdatewhouseCommandHander : IRequestHandler<UpdatewhouseCommand, ApiResult<object>>
    {
        public readonly IBaseRepository<WarehouseModel> WarehouseModelbaseRepository;
        public readonly DBHelper1 dBHelper;

        public UpdatewhouseCommandHander(IBaseRepository<WarehouseModel> warehouseModelbaseRepository, DBHelper1 dBHelper)
        {
            WarehouseModelbaseRepository = warehouseModelbaseRepository;
            this.dBHelper = dBHelper;
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<ApiResult<object>> Handle(UpdatewhouseCommand request, CancellationToken cancellationToken)
        {
            ApiResult<object> apiResult = new ApiResult<object>();
            var sql = $"update WarehouseModel set WarehouseName='{request.WarehouseName}',Defaultnot='{request.Defaultnot}',Disable='{request.Disable}',WHouseId='{request.WHouseId}',WHouseTypeId='{request.WHouseTypeId}',isdelete='{request.isdelete}',WarehouseNumber='{request.WarehouseNumber}' where WarehouseId='{request.WarehouseId}'";
            var r = dBHelper.NonQuery(sql);
            if (r > 0)
            {
                apiResult.Code = (ApiEnums)Renum.修改成功;
                apiResult.Message = Renum.修改成功.ToString();
                apiResult.Data = r;
            }
            else
            {
                apiResult.Code = (ApiEnums)Renum.修改失败;
                apiResult.Message = Renum.修改失败.ToString();
                apiResult.Data = r;
            }
            return Task.FromResult(apiResult);
        }
    }
}
